/* 
 * File:   client_AnimationPlayer.cpp
 * Author: agu
 * 
 * Created on 13 de junio de 2014, 18:18
 */

#include "client_AnimationPlayer.h"
#include <iostream>
#include <SDL2/SDL_keycode.h>
#define UP "00007|arriba"
#define DOWN "00006|abajo"
#define RIGHT "00008|derecha"
#define LEFT "00010|izquierda"
#define BOMBA "00006|bomba"
using std::cout;
using std::endl;

AnimationPlayer::AnimationPlayer(SDL_Renderer* renderer, const string path,
        int x, int y) : Animation(renderer, path, x, y) {
    //Velocidad de movimiento de la animacion
    this->vx = this->vy = 0.0;
}

void AnimationPlayer::updateMovement(SDL_Event event) {
    //If a key was pressed
    if (event.type == SDL_KEYDOWN && event.key.repeat == 0) {
        //Adjust the velocity
        switch (event.key.keysym.sym) {
            case SDLK_UP:
                this->vy = -1;
                this->keyNames->push(UP);
                this->currentSprite = this->spritesUp;
                break;
            case SDLK_DOWN:
                this->keyNames->push(DOWN);
                this->vy = 1;
                this->currentSprite = this->spritesDown;
                break;
            case SDLK_LEFT:
                this->vx = -1;
                this->keyNames->push(LEFT);
                this->currentSprite = this->spritesLeft;
                break;
            case SDLK_RIGHT:
               
                this->vx = 1;
                this->keyNames->push(RIGHT);
                this->currentSprite = this->spritesRight;
                break;
            case SDLK_SPACE:
                this->keyNames->push(BOMBA);
                break;
        }
    }//If a key was released
    else if (event.type == SDL_KEYUP && event.key.repeat == 0) {
        //Adjust the velocity
        switch (event.key.keysym.sym) {
            case SDLK_UP:
                this->vy = 0;
                break;
            case SDLK_DOWN:
                this->vy = 0;
                break;
            case SDLK_LEFT:
                this->vx = 0;
                break;
            case SDLK_RIGHT:
                this->vx = 0;
                break;
        }
    }
}

AnimationPlayer::~AnimationPlayer() {
}

void AnimationPlayer::updatePosition(int x, int y) {
    //Nueva posicion
    this->texture.setPosition(x, y);
}

void AnimationPlayer::setQueue(queue<string> *keys) {
    this->keyNames = keys;
}